﻿//*************************************************************************************************
// Tests for the CompareContextParams validation rule
//
// Copyright(c) Microsoft Corporation, 2008
//*************************************************************************************************
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WebAndLoadTestPluginsAndRules;
using Microsoft.VisualStudio.TestTools.WebTesting;

namespace HtmlTagInnerTextTests
{
    /// <summary>
    /// Summary description for CompareContextParamsTests
    /// </summary>
    [TestClass]
    public class CompareContextParamsTests
    {
        public CompareContextParamsTests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion
        
        [TestMethod]
        public void TestCompareContextParamRule()
        {
            WebTestDummy dummy = new WebTestDummy();
            string message;
            CompareContextParams compareParams = new CompareContextParams();
            compareParams.ContextParam1 = "p1";
            compareParams.ContextParam2 = "p2";
            WebTestContext context = dummy.Context;
            context.Add("p1", "a");
            context.Add("p2", "a");

            Assert.IsTrue(compareParams.Validate(context, out message));

            context["p2"] = "b";
            Assert.IsFalse(compareParams.Validate(context, out message));

            context["p2"] = "";
            Assert.IsFalse(compareParams.Validate(context, out message));

            // test missing param
            compareParams.ContextParam2 = "p4";
            Assert.IsFalse(compareParams.Validate(context, out message));

            // test unset param
            compareParams.ContextParam2 = "p3";
            context.Add("p5", null);
            Assert.IsFalse(compareParams.Validate(context, out message));
        }
    }
    public class WebTestDummy : WebTest
    {
        public override IEnumerator<WebTestRequest> GetRequestEnumerator()
        {
            throw new NotImplementedException();
        }
    }

}
